n = int(input())

for i in range(n):
    a, b = map(int, input().split())
    # 按位求和
    Sa = sum([int(i) for i in str(a)])
    Sb = sum([int(i) for i in str(b)])
    # 若a是Sb的整数倍
    if a % Sb == 0 and b % Sa != 0:
        print('A')
    elif b % Sa == 0 and a % Sb != 0:
        print('B')
    else:
        print('A' if a > b else 'B')
